﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace SGPFWebApp.Extensions
{
    public static class ExtensionMethods
    {
        public static void ResetFormControlValues(this System.Web.UI.Control parent)
        {
            foreach (System.Web.UI.Control c in parent.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    ResetFormControlValues(c);
                }
                else
                {
                    switch (c.GetType().ToString())
                    {
                        case "System.Web.UI.WebControls.TextBox":
                            ((TextBox)c).Text = "";
                            break;
                        case "System.Web.UI.WebControls.CheckBox":
                            ((CheckBox)c).Checked = false;
                            break;
                        case "System.Web.UI.WebControls.RadioButton":
                            ((RadioButton)c).Checked = false;
                            break;

                    }
                }
            }
        }

        public static void ClearControls(this ControlCollection collection) 
        { 
            foreach(System.Web.UI.Control c in collection) c.ResetFormControlValues();
        }
    }
}